//
//  YGJMyVC.m
//  ygj-customer-iOS
//
//  Created by apple on 16/11/10.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "YGJMyVC.h"
#import "YGJMyModel.h"
#import "YGJMyCell.h"
#import "YGJMyHeadCell.h"
#import "YGJQuickLoginVC.h"
#import "YGJUserInfoVC.h"

#define kImage @"img"
#define kText @"text"

@interface YGJMyVC ()

@end

@implementation YGJMyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    // Do any additional setup after loading the view from its nib.
    
    [self initData];
    
    [self setNavgationBarButton];
    
    
}

#pragma mark 设置导航栏左右按钮
-(void) setNavgationBarButton {
    
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"phone-old"] style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

#pragma mark 导航栏按钮事件

-(void) rightAction {
    NSLog(@"点击---->我的右侧导航按钮");
    
}


-(void) initData {
    _dataArray = [NSMutableArray array];
    
    NSDictionary * dic1 = @{kImage:@[@"my-off1"],kText:@[@"立即登录"]};
    [_dataArray addObject:dic1];
    
    NSDictionary * dic2 = @{kImage:@[@"zqb-icon"],kText:@[@"长期订单"]};
    [_dataArray addObject:dic2];
    
    NSDictionary * dic3 = @{kImage:@[@"address-icon",@"share-icon",@"vip_3",@"fwjs-icon",@"suggest-icon",@"set-icon",@"phone-icon"],kText:@[@"常用地址",@"分享给朋友",@"悦享VIP",@"服务介绍",@"意见反馈",@"设置",@"客服电话"]};
    [_dataArray addObject:dic3];
    
}

#pragma mark tableview代理
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary * dic = _dataArray[section];
    return [dic[kImage] count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString * str = @"cellId";
        
        YGJMyHeadCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (cell==nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"YGJMyHeadCell" owner:nil options:nil] lastObject];
        }
        cell.headImage.image = [UIImage imageNamed:[_dataArray[indexPath.section] objectForKey:kImage][indexPath.row]];
        cell.headText.text =[_dataArray[indexPath.section] objectForKey:kText][indexPath.row];
        return cell;

    }else {
        static NSString * cellId = @"cell";
        YGJMyCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell==nil) {
            cell =[[[NSBundle mainBundle] loadNibNamed:@"YGJMyCell" owner:nil options:nil] lastObject];
            cell.accessoryType = [UITableViewCell accessInstanceVariablesDirectly];
        }
        cell.img.image = [UIImage imageNamed:[_dataArray[indexPath.section] objectForKey:kImage][indexPath.row]];
        cell.text_label.text = [_dataArray[indexPath.section] objectForKey:kText][indexPath.row];
        
        return cell;
    }
    return nil;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 105;
    }
    return 45;
}
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 15;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //表格选中自动弹起
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section==0) {
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"login"] isEqualToString:@"login"])
        {
            self.hidesBottomBarWhenPushed=YES;
            YGJUserInfoVC * uivc = [[YGJUserInfoVC alloc] initWithNibName:@"YGJUserInfoVC" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:uivc animated:YES];
            self.hidesBottomBarWhenPushed=NO;
            
        } else {
            self.hidesBottomBarWhenPushed=YES;
            YGJQuickLoginVC * qlvc = [[YGJQuickLoginVC alloc] initWithNibName:@"YGJQuickLoginVC" bundle:[NSBundle mainBundle]];
            [self.navigationController pushViewController:qlvc animated:YES];
            self.hidesBottomBarWhenPushed=NO;
        }
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
